Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Break if DEBUG_ASSERT is encountered #2911

Merged
merged 6 commits into from
Aug 11, 2020

Conversation

Holzhaus
Copy link
Member

@Holzhaus Holzhaus commented Jul 5, 2020

TODO:

If you build Mixxx in debug mode, this makes sure that debug assertions lead to test failures. This implementation is far from perfect, it does not work in release builds (since debug assertions are stripped in that case), but it would require some bigger changes to make it possible to enable debug assertions for tests but not mixxx itself. For now, always make sure to build tests in debug mode or with DEBUG_ASSERTS_FATAL=ON.

Note: This will lead to a bunch of test failures. Not sure if we want to merge this before we fix them, because it will lead to failed CI builds in unrelated branches.

@Holzhaus Holzhaus added this to the 2.3.0 milestone Jul 5, 2020
@Holzhaus Holzhaus requested a review from uklotzde July 5, 2020 01:06
@daschuer
Copy link
Member

daschuer commented Jul 5, 2020

I have not yet understand how logging relates the DEBUG_ASSERT.

But let's release all from headaches and hold this back until the all test are working.

@uklotzde
Copy link
Contributor

uklotzde commented Jul 5, 2020

#2912

@daschuer
Copy link
Member

daschuer commented Jul 5, 2020

I grepped for MIXXX_DEBUG_ASSERTIONS_FATAL and discovered it's enabled by installing a Qt message handler

It sounds like his should be decoupled. Right?

@Holzhaus
Copy link
Member Author

Holzhaus commented Jul 5, 2020

I grepped for MIXXX_DEBUG_ASSERTIONS_FATAL and discovered it's enabled by installing a Qt message handler

It sounds like his should be decoupled. Right?

Not necessarily. The elephant in the room is that tests will only work reliably (as in: they fail when shit hits the fan) when the MIXXX_BUILD_DEBUG preprocessor definition is set when compiling Mixxx. Otherwise DEBUG_ASSERT statements are stripped from the source, so tests will pass even though they do something nasty. That means we always need to build in debug mode during development.

The only way around this that I can think of would be to compile the mixxx-lib cmake target twice, one for the mixxx executable (possibly without debug asssertions) and one for the tests (always with debug assertions). I don't think that's feasible.

Let's always do debug builds on the CI for PRs and testing our branches, and we can add a second build stage that is only executed when operating on a tag (not a PR/branch) and builds in release mode for deployment.

@Holzhaus
Copy link
Member Author

Holzhaus commented Jul 5, 2020

My last commit should make CI builds fail until the debug assertions are fixed. When DEBUG_ASSERTIONS_FATAL has been set, we should enable DEBUG_ASSERT statements even in Release builds. For CMake I added a status message in that case.

For CI testing we also just switch to debug builds, but I think if a user explicitly enabled the DEBUG_ASSERTIONS_FATAL flag, it should be honored independent of the build type IMHO.

@uklotzde
Copy link
Contributor

uklotzde commented Jul 5, 2020

I will try to fix some issues in ControlObject/ControlPrivateDouble that seem to affect us now. Only the bare minimum, no more.

@Holzhaus
Copy link
Member Author

Holzhaus commented Jul 5, 2020

I will try to fix some issues in ControlObject/ControlPrivateDouble that seem to affect us now. Only the bare minimum, no more.

Can you elaborate what issues you're referring to?

@uklotzde
Copy link
Contributor

uklotzde commented Jul 5, 2020

#2918 Issues like leaking controls that are not removed from the internal, static hash map after finishing tests and that are causing subsequent tests to fail with debug assertions when registering new ControlObject instances.

@Holzhaus Holzhaus force-pushed the test-debug-assert branch from a2fa97c to 9ffeafe Compare July 5, 2020 23:36
@Holzhaus
Copy link
Member Author

Holzhaus commented Jul 5, 2020

I rebased to update the test failure logs (this PR is so small that I don't think rebasing is an issue here).

@uklotzde
Copy link
Contributor

uklotzde commented Jul 7, 2020

I rebased to update the test failure logs (this PR is so small that I don't think rebasing is an issue here).

Yes, please always rebase after prerequisite PRs have been merged. This PR should remain the icing on the cake, keeping track of the those changes until the tests finally succeed.

@uklotzde
Copy link
Contributor

@daschuer Ping. We need your support for fixing the AutoDJ assertions and test failures.

@uklotzde
Copy link
Contributor

uklotzde commented Jul 10, 2020

Please open a separate PR for the /lib integration works. wrong PR

@Holzhaus Holzhaus force-pushed the test-debug-assert branch 2 times, most recently from 94dd960 to d768229 Compare July 15, 2020 14:27
@Holzhaus Holzhaus force-pushed the test-debug-assert branch from d768229 to 9d13cb0 Compare August 3, 2020 21:19
Holzhaus added a commit to Holzhaus/mixxx that referenced this pull request Aug 4, 2020
Until now, the `PlayerInfo` singleton was instantiated implicitly when
it was first accessed. This commit makes the instantiation explicit by
adding a dedicated `PlayerInfo::create()` method.

When running tests directly via `mixxx-test` (i.e. not a via `ctest`),
all tests will be executed in the *same* process. Thus, the singleton
will be instantiated by the first test that accessses the instance, but
stay alive until `mixxx-test` is terminated.

The `PlayerInfo` instance will repeatedly call
`updateCurrentlyPlayingDeck()` through the `timerEvent()` mehtod during
its lifetime. This will access some COs, e.g. `[Master],num_decks`.
Depending on the currently running test, these COs may or may not be
present. When `QCoreApplication::processEvents()` is called, there might
be a `timerEvent()` in the queue and will cause CO access.  If the CO is
*not* present for that test, the test will throw a `DEBUG_ASSERT`.

By making the singleton instantiation more explicit, we can add
`PlayerInfo::create()` and `PlayerInfo::destroy()` calls only to the
constructor/destructor of text fixtures that need it, and ensure that
the timer doesn't cause failed debug assertions in unrelated tests.

This fixes the remaining `DEBUG_ASSERT` issues and paves the way for
merging PR mixxxdj#2911.
Holzhaus added a commit to Holzhaus/mixxx that referenced this pull request Aug 4, 2020
Until now, the `PlayerInfo` singleton was instantiated implicitly when
it was first accessed. This commit makes the instantiation explicit by
adding a dedicated `PlayerInfo::create()` method.

When running tests directly via `mixxx-test` (i.e. not a via `ctest`),
all tests will be executed in the *same* process. Thus, the singleton
will be instantiated by the first test that accessses the instance, but
stay alive until `mixxx-test` is terminated.

The `PlayerInfo` instance will repeatedly call
`updateCurrentlyPlayingDeck()` through the `timerEvent()` mehtod during
its lifetime. This will access some COs, e.g. `[Master],num_decks`.
Depending on the currently running test, these COs may or may not be
present. When `QCoreApplication::processEvents()` is called, there might
be a `timerEvent()` in the queue and will cause CO access.  If the CO is
*not* present for that test, the test will throw a `DEBUG_ASSERT`.

By making the singleton instantiation more explicit, we can add
`PlayerInfo::create()` and `PlayerInfo::destroy()` calls only to the
constructor/destructor of text fixtures that need it, and ensure that
the timer doesn't cause failed debug assertions in unrelated tests.

This fixes the remaining `DEBUG_ASSERT` issues and paves the way for
merging PR mixxxdj#2911.
@Holzhaus Holzhaus force-pushed the test-debug-assert branch from 9d13cb0 to 854d005 Compare August 5, 2020 08:45
@Holzhaus
Copy link
Member Author

Holzhaus commented Aug 5, 2020

I rebased on latest 2.3, all tests pass now both with ctest and when running mixxx-test directly. Merge?

@uklotzde
Copy link
Contributor

uklotzde commented Aug 8, 2020

Please rebase once again.

We might also need to reduce the log level. The CI builds now fail because of the huge amount of debug log messages in some tests.

@Holzhaus Holzhaus force-pushed the test-debug-assert branch from 854d005 to d9a31e5 Compare August 8, 2020 11:23
@Holzhaus
Copy link
Member Author

Holzhaus commented Aug 8, 2020

Done. CTest hides the test output and only shows it if a test failed. So if the build is terminated due to the long output, that should be a side effect of the failing test, not the cause.

@uklotzde
Copy link
Contributor

uklotzde commented Aug 8, 2020

Done. CTest hides the test output and only shows it if a test failed. So if the build is terminated due to the long output, that should be a side effect of the failing test, not the cause.

I don't think so. The GlobalTrackCache test is aborted while running without any failures:

Debug []: GlobalTrackCache - Cache miss - allocating track ["/Users/travis/build/mixxxdj/mixxx/src/test/id3-test-data/cover-test.flac" | "/Users/travis/build/mixxxdj/mixxx/src/test/id3-test-data/cover-test.flac" | -1]


Debug []: GlobalTrackCa

The job exceeded the maximum log length, and has been terminated.

@uklotzde
Copy link
Contributor

uklotzde commented Aug 8, 2020

The log output might not be shown, but it seems to be written in any case.

@uklotzde
Copy link
Contributor

uklotzde commented Aug 8, 2020

Change log level from Debug to Info during tests:
uklotzde@eb76a9b

Debug assertions still cause test failures as intended (tested locally). Waiting for CI:
https://travis-ci.org/github/uklotzde/mixxx/builds/716097598

Seems to work, please cherry-pick.

@Holzhaus
Copy link
Member Author

Holzhaus commented Aug 8, 2020

Hmm I'm still not sure if the log level messages is the actual cause of the issue but if you checked it then it probably is. However, I'd rather not disable debug messages for tests globally. Maybe we can add a flag or set it via an env var, so that you can still see debug messages when running locally. I'll poke around tomorrow.

@Holzhaus
Copy link
Member Author

Holzhaus commented Aug 10, 2020

For the macOS/CMake build, i think the test times out:

271/616 Test #271: GlobalTrackCacheTest.concurrentDelete ...........................................***Timeout 30.03 sec

See Line 4090: https://travis-ci.org/github/mixxxdj/mixxx/jobs/716093492#L4090

A timeout is considered a failure, which is why ctest then starts to print the logging output (which Travis cuts off). But the actual issue seems to be the timeout after 30 seconds.

For SCons, the build fails due to the verbose log, so changing the test log level is needed anyway as long as we keep SCons. When we drop it, it'd prefer to go back to debug tbh.

@uklotzde
Copy link
Contributor

Thanks for customizing the log level during tests! Please fix the remaining formatting issues.

Detailed logging is not particularly important for the CI builds which are only supposed to detect test failures. In case of any failures, you need to repeat the affected tests anyway. Test failures should be reproducible and you could enable more detailed logging on demand when analyzing failing tests.

@uklotzde
Copy link
Contributor

uklotzde commented Aug 11, 2020

The time out for GlobalTrackCacheTest.concurrentDelete is tight and it fails infrequently on the poorly performing macOS VMs on Travis. Usually, it finishes in about ~25 sec. Unrelated to the changes in this PR.

@uklotzde
Copy link
Contributor

These changes greatly improve the confidence in our testing efforts and finally enable a huge amount of additional checks to detect issues early. Thank you!

LGTM

@uklotzde uklotzde merged commit fcaac7b into mixxxdj:2.3 Aug 11, 2020
@uklotzde
Copy link
Contributor

Master builds may now fail until #3006 has been merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants